//
//  UIBarButtonItem+RightNavBarBtn.m
//  Property
//
//  Created by Luoh on 2018/5/15.
//  Copyright © 2018年 rp.wang. All rights reserved.
//

#import "UIBarButtonItem+RightNavBarBtn.h"

@implementation UIBarButtonItem (RightNavBarBtn)

/**
 *  右边按钮（图片）
 */
+ (UIBarButtonItem *)initWithImage:(UIImage *)image target:(id)target action:(SEL)selector {
    UIButton *rightButton = ({
        UIButton *moreButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [moreButton setFrame:CGRectMake(0, 0, 30, 30)];;
        [moreButton addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
        [moreButton setImage:image forState:UIControlStateNormal];
        [moreButton setFont:[UIFont fontWithName:@"SourceHanSansCN-Medium" size:16]];
        
        moreButton;
    });
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
    [view addSubview:rightButton];
    
    UIBarButtonItem *rightBarButton = [[UIBarButtonItem alloc] initWithCustomView:view];
    
    return rightBarButton;
}

/**
 *  右边按钮（标题）
 */
+ (UIBarButtonItem *)initWithTitle:(NSString *)title target:(id)target action:(SEL)selector {
    
    UIButton *rightButton = ({
        
        UIButton *moreButton = [UIButton buttonWithType:UIButtonTypeCustom];
        
        [moreButton setFrame:CGRectMake(0, 0, 30, 30)];;
        [moreButton addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
        [moreButton setTitle:title forState:UIControlStateNormal];
        [moreButton setFont:[UIFont fontWithName:@"SourceHanSansCN-Medium" size:16]];
        
        moreButton;
    });
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];
    [view addSubview:rightButton];
    
    UIBarButtonItem *rightBarButton = [[UIBarButtonItem alloc] initWithCustomView:view];
    
    return rightBarButton;
}

+ (UIBarButtonItem *)initLeftButtonWithImage:(UIImage *)image target:(id)target action:(SEL)selector {
    
    UIButton * leftButton = ({
        UIButton * leftNavButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [leftNavButton setFrame:CGRectMake(-20, 0, 44, 44)];
        [leftNavButton addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
        [leftNavButton setImage:image forState:UIControlStateNormal];
        [leftNavButton setFont:[UIFont fontWithName:@"SourceHanSansCN-Medium" size:16]];
        
        leftNavButton;
    });
    
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
    [view addSubview:leftButton];
    
    UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithCustomView:view];
    
    return leftBarButton;
}

@end
